home *** CD-ROM | disk | FTP | other *** search
/ Ahoy 1987 May / Ahoy_Magazine_87-05_1987_Double_L_Side_B.d64 / star trek.txt < prev    next >
Text File  |  2022-10-26  |  7KB  |  241 lines

  1. STAR TREK DATA BASE
  2.  
  3. by Len Lindsay
  4.  
  5. I wanted to write a program to
  6. demonstrate file handling, especially
  7. with random files. Star Trek
  8. presented itself as an excellent
  9. topic. This science fiction show has
  10. been on the air for 20 years now,
  11. with a total of 79 episodes. I
  12. created a data base system that can
  13. easily keep track of all of these
  14. shows. Very little in this data base
  15. is specific to Star Trek.
  16.  
  17. I used 8 fields of 27 characters each
  18. to store the data for a show, plus
  19. two extra fields that you can decide
  20. how to use. The titles for each of
  21. the 8 main fields can vary depending
  22. on what information you wish to keep
  23. track of. For my Star Trek shows I
  24. chose the following:
  25.  
  26. Show Name :
  27. Writer    :
  28. Air Date  :
  29. Guest Star:
  30.           :
  31. Characters:
  32.           :
  33. Location  :
  34.  
  35. I've also provided two extra "user"
  36. fields. The first is an "Star Date"
  37. of 6 characters. Currently the star
  38. date that is mentioned (if any) is
  39. entered, but you could put the video
  40. tape number here, the name of your
  41. friend who has this show on tape, or
  42. a short comment on the show. The
  43. other field is only one character. It
  44. can be used to rate each show (A,B,C,
  45. etc). I use it to mark the shows that
  46. I have seen. If marked, the entire
  47. show is shown in reverse (white on
  48. black).
  49.  
  50. Charles Phillips was nice enough to
  51. type in all 79 episodes. Once you
  52. have a data base filled with
  53. information, it is easy and fun to
  54. use.
  55.  
  56. For example, let's say your favorite
  57. author is Harlen Ellison. Using the
  58. data base system, you can choose the
  59. Search option, and it will list every
  60. show written by him. The nice thing
  61. about this is that the system uses
  62. COMAL's IN operator to find the
  63. matches. Thus, you can ask the system
  64. to look for "ar" and it will find
  65. both Harlen Ellison and David
  66. Garrold. Remember, the search is very
  67. picky on upper or lower case. Thus,
  68. Cyb will not match CYB.
  69.  
  70. Since this system uses a random file
  71. for its data, it is easy to randomly
  72. display any show. Just type in the
  73. show number, and instantly (almost)
  74. its information is displayed. To see
  75. the next show just type + (plus
  76. sign). To see the previous show type
  77. - (minus sign).
  78.  
  79. Another nice feature of this system
  80. is BROWSE. It allows you to scan over
  81. all the entries, one after another,
  82. starting after the show currently
  83. displayed. It even has a variable
  84. pause between shows. Five seconds is
  85. the default, but for a fast scan, use
  86. 0 for the length of pause.
  87.  
  88. NOTES ABOUT THE PROGRAM
  89.  
  90. The variable mark$ is used to
  91. determine whether or not the
  92. information display is normal or
  93. reverse field. The seventh line of
  94. the program is:
  95.  
  96. display(mark$<> " ")
  97.  
  98. Display is the name of the procedure
  99. that prints the information about the
  100. show to the screen. It has one
  101. numeric parameter. If the parameter
  102. is FALSE (a value of 0) then the
  103. information is displayed normally. If
  104. it is TRUE (a value not equal to 0)
  105. then the information is displayed in
  106. reverse field. Mark$<> " " is a
  107. comparison that will always be either
  108. TRUE or FALSE, thus providing the
  109. proper parameter.
  110.  
  111. Notice that to have the reverse
  112. display, each value printed must be
  113. the correct length because the
  114. reverse field will stop at the last
  115. character. The length used in this
  116. program is 27. Thus, if the show name
  117. is less than 27 characters, I had to
  118. do something to print reverse field
  119. spaces at the end of the name. I let
  120. COMAL take care of this for me by
  121. using substring notation when
  122. inputing this data (from both
  123. keyboard input and file input). For
  124. example:
  125.  
  126. dim name$ of 27
  127. input "name:": name$
  128. print chr$(18)+name$
  129. print "length is";len(name$)
  130. input "name:": name$(1:27)
  131. print chr$(18)+name$
  132. print "length is";len(name$)
  133.  
  134. Run that program and type TEST as the
  135. name both times it asks. The first
  136. time it has a length of 4. The last
  137. time it has a length of 27 (the value
  138. was padded with spaces at the end).
  139. Printing it each time in reverse
  140. field shows how the (1:27) takes care
  141. of formatting problems for me!
  142.  
  143. Calculating the correct record length
  144. is also important when using random
  145. files. Use the maximum possible
  146. length as the length for the file. In
  147. this case I had 8 fields of 27
  148. characters, 1 field of 11 characters,
  149. and 1 field of 1 character. Since
  150. each field is a string, I also must
  151. add a 2 byte counter for each field.
  152. Thus 8*29 plus 13 plus 3 gives 248.
  153. The smallest record size I can use
  154. and be sure to hold all possible data
  155. is 248, which I set in the start'up
  156. procedure.
  157.  
  158. To calculate record length when using
  159. WRITE FILE remember these rules:
  160.  
  161. * A real number always needs 5 bytes
  162. * An integer needs 2 bytes in COMAL
  163. 2.0
  164.   An integer needs 5 bytes in COMAL
  165. 0.14
  166. * A string needs its maximum length
  167.   PLUS 2 bytes for a length counter
  168.  
  169. Knowing how many records have been
  170. written is also important when using
  171. random files. If you attempt to read
  172. a record past the last existing one,
  173. an error occurs! A common way to keep
  174. track of the last record number is to
  175. WRITE it into the first record of the
  176. file:
  177.  
  178. write file 2,1: last'record
  179.  
  180. Last'record is a variable that holds
  181. the number of the last record written
  182. to the file. Now, each time you use
  183. that file, you can simply read the
  184. last record number from the file like
  185. this:
  186.  
  187. read file 2,1: last'record
  188.  
  189. The only side effect of this is that
  190. you cannot use the first record for
  191. regular data. Often, this is not a
  192. problem. For example, in our order
  193. processing system programs (running
  194. under IBM PC COMAL) COMAL Today
  195. subscribers are part of a random
  196. file, stored by their subscriber
  197. number. Since I use the first record
  198. to hold the last subscriber's number,
  199. I started my subscriber count with 2.
  200. Thus there is no subscriber number 1.
  201.  
  202. But in keeping track of Star Trek
  203. shows, there is a show number 1.
  204. Since it can't be written into record
  205. number 1, we simply add 1 to the show
  206. number to give the record number
  207. (read this sentence twice - it makes
  208. sense). Thus show number 1 is stored
  209. in record number 2. Both read'record
  210. and write'record procedures do the
  211. record number conversion.
  212.  
  213. Another thing I try to do is keep my
  214. files closed as much as possible. On
  215. a Commodore disk, all files must be
  216. properly closed or they can't be
  217. opened later. So, I take precautions
  218. (in case of a power outage etc.) and
  219. keep the file closed when it is not
  220. directly being used. For example,
  221. while searching the file for matches,
  222. I use the procedure read'record
  223. directly, and don't close the file
  224. after each record is read. I only
  225. close the file after I find a match.
  226. However, when just getting
  227. information about one show, I have
  228. the procedure read'it which first
  229. opens the file, then reads the
  230. record, then closes the file. Thus
  231. the file is closed while I look at
  232. that record (and possibly edit it).
  233. Note that I always close the file
  234. after I write to it. Thus I only have
  235. one write'record procedure.
  236.  
  237. Remember, the data is one of the most
  238. important parts of this data base
  239. system! The data is in the file
  240. "ran.startrek".
  241.